<template>
	<view class="departmentRank padding">
		<view class="deRankALL">
			<h3 class="margin-bottom">部门总排名</h3>
			<view class="cu-list menu-avatar" >
				<view class="cu-item" v-for="(item,index) in totalrank" :key="item+index">
					<view class="myRank_logo" style="position: absolute;left: 36rpx;font-size: 46rpx">
						<text class="text-grey">{{index+1}}</text>
					</view>
					<view class="content" style="left: 226rpx;">
						<view class="text-grey">
							<view class="text-cut">{{item.department_name}}</view>
						</view>
					</view>
					<view class="action" style="width: 140rpx;">
						<text class="bg-green text-xs" style="padding: 12rpx;border-radius: 18rpx;">积分：{{item.sum_integral}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="deRankAvg margin-top">
			<h3 class="margin-bottom">部门平均排名</h3>
			<view class="cu-list menu-avatar" >
				<view class="cu-item" v-for="(item,index) in avgrank" :key="item+index">
					<view class="myRank_logo" style="position: absolute;left: 36rpx;font-size: 46rpx">
						<text class="text-grey">{{index+1}}</text>
					</view>
					<view class="content" style="left: 226rpx;">
						<view class="text-grey">
							<view class="text-cut">{{item.department_name}}</view>
						</view>
					</view>
					<view class="action" style="width: 140rpx;">
						<text class="bg-green text-xs" style="padding: 12rpx;border-radius: 18rpx;">积分：{{item.avg_integral}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				totalrank:[
					{
						sum_integral:0,
						department_name:''
					}
				],
				avgrank:[
					{
						avg_integral:0,
						department_name:''
					}
				],
			}
		},
		onLoad() {
			this.getSumRankData()
		},
		methods:{
			async getSumRankData(){
				let res = await this.$myRuquest({
					url:'/department_ranking/'
				})
				this.totalrank = res.data.sum
				this.avgrank = res.data.avg
				function compare(property){
					return function(a,b){
						var value1 = a[property];
						var value2 = b[property];
						return value1 - value2;
					}
				}
				this.totalrank.sort(compare('sum_integral')).reverse()
				this.avgrank.sort(compare('avg_integral')).reverse()
			}
		}
	}
</script>

<style>
</style>
